package com.sharer.last.controller;

import com.sharer.last.base.constant.CommonConstant;
import com.sharer.last.base.model.R;
import com.sharer.last.model.dto.sitesetting.FriendSiteSettingDTO;
import com.sharer.last.model.dto.sitesetting.SiteSettingUpdateDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.sharer.last.annotation.OperationLogger;
import com.sharer.last.model.po.SiteSettingPO;
import com.sharer.last.service.SiteSettingService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 站点设置后台管理
 *
 * @ClassName SiteSettingAdminController
 * @Author wangjin
 * @Date 2023/5/5 21:04
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.BLOG_ADMIN_API + "/site/setting")
public class SiteSettingAdminController {
    @Resource
    SiteSettingService siteSettingService;

    /**
     * 查询网页标题后缀
     *
     * @return
     */
    @GetMapping("/webTitleSuffix")
    public R getWebTitleSuffix() {
        return R.success(siteSettingService.getWebTitleSuffix());
    }

    /**
     * 获取所有站点配置信息
     *
     * @return
     */
    @GetMapping("/list")
    public R list() {
        Map<String, List<SiteSettingPO>> map = siteSettingService.selectAllListByTypeGrouping();
        return R.success(map);
    }

    /**
     * 更新站点配置信息
     *
     * @param dto
     * @return
     */
    @OperationLogger("更新站点配置信息")
    @PutMapping("/updateAll")
    public R updateAll(@RequestBody @Validated SiteSettingUpdateDTO dto) {
        siteSettingService.updateAllSiteSetting(dto);
        return R.handle();
    }

    /**
     * 修改友链页面评论开放状态
     *
     * @return
     */
    @OperationLogger("修改友链页面评论开放状态")
    @PutMapping("/updateFriendCommentEnabled")
    public R updateFriendCommentEnabled(@RequestBody FriendSiteSettingDTO dto) {
        siteSettingService.updateFriendCommentEnabled(dto.getCommentEnabled());
        return R.handle();
    }

    /**
     * 修改友链页面content
     *
     * @return
     */
    @OperationLogger("修改友链页面信息")
    @PutMapping("/updateFriendContent")
    public R updateFriendContent(@RequestBody FriendSiteSettingDTO dto) {
        siteSettingService.updateFriendContent(dto.getContent());
        return R.handle();
    }

}
